package com.example.api;

import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

public class MailManger {

    private MailSender mailSender; //发送者

    private SimpleMailMessage simpleMailMessage;//发送模板

    public MailSender getMailSender() {
        return mailSender;
    }

    public void setMailSender(MailSender mailSender) {
        this.mailSender = mailSender;
    }

    public SimpleMailMessage getSimpleMailMessage() {
        return simpleMailMessage;
    }

    public void setSimpleMailMessage(SimpleMailMessage simpleMailMessage) {
        this.simpleMailMessage = simpleMailMessage;
    }

    /**
     * 邮件发送
     * @param userCode 接收者的邮箱
     * @param active 该邮箱对应的激活码
     */
    public void  placeOrder(String userCode, String active){
        //SimpleMailMessage 只能发送text文件
        SimpleMailMessage simpleMailMessage =new SimpleMailMessage(this.simpleMailMessage);

        simpleMailMessage.setTo(userCode);

        simpleMailMessage.setText(active);
        this.mailSender.send(simpleMailMessage);
    }
}
